<template>
  <span>
    <el-button type="primary" size="medium" @click="dialogVisible = true">批量上下架</el-button>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <div>
        <el-radio v-model="radio" :label="1">批量上架</el-radio>
        <el-radio v-model="radio" :label="0">批量下架</el-radio>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </span>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      radio: 1
    }
  },
  created() {
  },
  methods: {
    submit() {
      const loading = this.$loading({
        lock: true,
        text: '正在批量操作',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      this.axios.get(`/manage/contents`, { params: { '@filter': `entity.getCategory().getType().getSlug() == "video"` }}).then((res) => {
        const promise = []
        for (const i of res.data) {
          promise.push({
            id: i.id,
            enabled: this.radio
          })
          // promise.push(
          //   this.axios.put(`/manage/contents/${i.id}`, { enabled: this.radio })
          // )
        }
        this.axios.post(`/manage/contents/batch-update`, promise, { params: { '@mode': 'mixed', '@basis': 'id' }}).then((res) => {
          loading.close()
          this.dialogVisible = false
          this.$message.success('操作成功！')
          location.reload()
        })
      })
    }
  }
}
</script>
